/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trefliq.EJB.sessionbeans;

import java.sql.Date;
import javax.annotation.security.PermitAll;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import trefliq.EJB.entities.Credit;
import trefliq.EJB.entities.Movie;
import trefliq.EJB.entities.MovieGenre;

/**
 *
 * @author adam
 */
@Stateless
@LocalBean
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@PermitAll
public class MovieGenreBean {
    @PersistenceContext(unitName="trefliqPU")
    private EntityManager _em;


    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN, SecurityRole.EMPLOYEE})
    public boolean CreateMovieGenre(long movieid, long genre) {
        MovieGenre instance = new MovieGenre(movieid, genre);
         
        try {
            _em.persist(instance);
            _em.close();
        }
        catch (Exception e) {
            return false;          
        }
        return true;
    }

    //TODOSEC: @RolesAllowed({SecurityRole.ADMIN, SecurityRole.EMPLOYEE})
    public boolean DeleteMovieGenre(long movieid, long genre) {
        MovieGenre instance = new MovieGenre(movieid, genre);
         
        try {
            _em.remove(instance);
            _em.close();
        }
        catch (Exception e) {
            return false;          
        }
        return true;
    }

}
